<template>
<div class="article-list">

  <!-- <div style="display:flex;align-items: center;justify-content: space-between;margin:0 0 10px;">
      <div style="display:flex;align-items: center;">
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
          <el-form-item label="标题">
            <el-input clearable size="small" v-model="formInline.title" placeholder="请输入新闻标题"></el-input>
          </el-form-item>
          <el-form-item label="状态">
            <el-select clearable size="small" v-model="formInline.state" placeholder="请选择">
              <el-option
                v-for="item in [{
                  value: '1',
                  label: '启用'
                },{
                  value: '0',
                  label: '禁用'
                },]"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button size="small" type="primary" @click="onSubmit">搜索</el-button>
            <el-button size="small" @click="resetSubmit">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div>
        <el-button size="small" type="primary" @click="add">发布文章</el-button>
      </div>
    </div> -->

  <el-table ref="multipleTable" v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row empty-text="暂无数据">
    <el-table-column label="课程海报" width="180" align="center">
      <template slot-scope="scope">
        <img :src="scope.row.coverUrl" alt="" style="width:80px;height:40px;">
      </template>
    </el-table-column>
    <el-table-column label="课程视频" width="180" align="center">
      <template slot-scope="scope">
        <div style="width:100%;height:100%;position:absolute;top:0;left:0;display:flex;align-items:center;justify-content:center;background:rgba(255,255,255,.6)">
          <i @click="openVideo(scope.row)" style="cursor:pointer;font-size:30px;color:#333;" class="el-icon-video-play"></i>
        </div>
        <img :src="`${scope.row.videoUrl}?vframe/jpg/offset/1`" alt="" style="width:80px;height:40px;">
      </template>
    </el-table-column>
    <el-table-column label="课程名称" width="200">
      <template slot-scope="scope">
        {{ scope.row.name }}
      </template> 
    </el-table-column>
    <el-table-column label="主讲教师" width="200">
      <template slot-scope="scope">
        {{ scope.row.teacherList&&scope.row.teacherList.length?scope.row.teacherList[0].realName:'' }}
      </template>
    </el-table-column>
    <el-table-column label="课程简介" :show-overflow-tooltip="true" width="200">
      <template slot-scope="scope">
        {{ scope.row.des }}
      </template>
    </el-table-column>
    <!-- <el-table-column label="费用" width="100" align="center">
      <template slot-scope="scope">
        {{ scope.row.fee?scope.row.fee:'免费' }}
      </template>
    </el-table-column> -->
    <!-- <el-table-column label="试卷" width="300">
      <template slot-scope="scope">
        <div v-if="scope.row.exercisePaperDetail&&scope.row.exercisePaperDetail.paperName" style="padding: 2px 0;">
          练习试卷：<el-tag @click="goPaper(scope.row.exercisePaperDetail.id, '/paper/test', scope.row.exercisePaperDetail.paperName)" style="cursor:pointer;" size="small">{{ scope.row.exercisePaperDetail.paperName }}</el-tag>
        </div>
        <div v-if="scope.row.workPaperDetail&&scope.row.workPaperDetail.paperName" style="padding: 2px 0;">
          作业试卷：<el-tag @click="goPaper(scope.row.workPaperDetail.id, '/paper/task', scope.row.workPaperDetail.paperName)" style="cursor:pointer;" size="small">{{ scope.row.workPaperDetail.paperName }}</el-tag>
        </div>
        <div v-if="scope.row.examinationPaperDetail&&scope.row.examinationPaperDetail.paperName" style="padding: 2px 0;">
          考试试卷：<el-tag @click="goPaper(scope.row.examinationPaperDetail.id, '/paper/exam', scope.row.examinationPaperDetail.paperName)" style="cursor:pointer;" size="small">{{ scope.row.examinationPaperDetail.paperName }}</el-tag>
        </div>
      </template>
    </el-table-column> -->
    <!-- <el-table-column label="创建人" width="100">
      <template slot-scope="scope">
        {{ scope.row.creater }}
      </template>
    </el-table-column> -->
    <el-table-column label="创建时间" width="200">
      <template slot-scope="scope">
        {{ scope.row.createTime }}
      </template>
    </el-table-column>
  </el-table>
  <div style="margin:10px 0 0 0;text-align:right;">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageObj.pageNum"
      :page-sizes="[10, 30, 50, 100]"
      :page-size="pageObj.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageObj.total">
    </el-pagination>
  </div>
</div>
</template>

<script>
import {
  getListApi,
} from '@/api/column'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: [],
      listLoading: true,
      currentPage: 1,
      formInline: {
        isShow: '',
        classify: '',
        state: '',
        title: '',
      },
      pageObj: {
        pageSize: 10,
        pageNum: 1,
        total: 0,
      },
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    onSubmit() {
      this.fetchData()
    },
    add() {
      this.$router.push({
        path: '/article/add'
      })
    },
    changeTop(id, isShow) {
      changeTopApi({
        id: id,
        isShow: isShow
      }).then((res) => {
        this.fetchData()
      })
    },
    changeState(row, state) {
      changeStateApi({
        id: row.id,
        state: state
      }).then((res) => {
        this.fetchData()
      })
    },
    getTypeList() {
      gettypeListApi({
        pageSize: 100,
        pageNum: 1,
      }).then((res) => {
        this.typeList = res.data.result.map((r) => {
          return {
            value: r.id,
            label: r.name
          }
        })
      })
    },
    edit(row) {
      this.$router.push({
        path: '/article/edit',
        query: {
          editId: row.id
        }
      })
    },
    del(row) {
      deleteApi({
        ids: row.id
      }).then((res) => {
        this.fetchData()
      })
    },
    resetSubmit() {
      this.formInline.state = ''
      this.formInline.title = ''
      this.pageObj.pageSize = 10
      this.pageObj.pageNum = 1
      this.pageObj.total = 0
      this.fetchData()
    },
    fetchData() {
      this.listLoading = true
      getListApi({
        questionType: 4,
        pageSize: this.pageObj.pageSize,
        pageNum: this.pageObj.pageNum,
      }).then(response => {
        this.list = response.data.result
        this.pageObj.total = response.data.total
        this.listLoading = false
      })
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pageObj.pageSize = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.pageObj.pageNum = val
      this.fetchData()
    }
  }
}
</script>

<style lang="scss" scoped>
   .article-list{
     padding: 20px;
     .el-form-item{
       margin-bottom: 0;
     }
   }
</style>
